<template>
  <div>
    <el-dialog :visible.sync="showDialog" :before-close="check" title="身份标识">
      <el-table
        :data="list"
        border
        style="width: 100%"
      >
        <el-table-column label="平台名称">
          <template slot-scope="scope">
            {{ scope.row.platformName }}
          </template>
        </el-table-column>
        <el-table-column label="平台账号">
          <template slot-scope="scope">
            {{ scope.row.userId }}
          </template>
        </el-table-column>
        <el-table-column label="操作" width="300">
          <template slot-scope="scope">
            <el-button
              type="primary"
              plain
              round
              size="mini"
              icon="el-icon-third-eye"
              @click="watch(scope.row.userId,scope.row.platformId)"
            >查看</el-button>
            <el-button
              type="primary"
              plain
              round
              size="mini"
              icon="el-icon-third-pingtaijiyewujiankong"
              @click="cancelConnect(scope.row)"
            >取消关联</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- :id="ids" -->
    <watch-info :dialog-table-visible="dialogTableVisible" :idd="idd" :plat-idd="platIdd" @closeDialog="closeDialog"/>
  </div>
</template>
<script>
import secret from '@/utils/secret'
import { connect, cancel } from '@/api/liantong'
import { mapGetters } from 'vuex'
import WatchInfo from './watch.vue'
export default {
  name: 'ConnectPlat',
  components: {
    WatchInfo: WatchInfo
  },
  props: {
    // 遮罩
    connectDialog: {
      type: Boolean,
      default: false
    },
    ids: {
      type: String,
      default: null
    },
    searchRequest: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      showDialog: false,
      list: null,
      id: null,
      dialogTableVisible: false,
      idd: null,
      requestTerm: null,
      sitation: false,
      idClear: null,
      platIdd: null // 平台id
    }
  },
  computed: {
    ...mapGetters(['assignment', 'token'])
  },
  watch: {
    ids(newVal) {
      this.idClear = newVal
    },
    connectDialog(newVal) {
      this.showDialog = newVal
      if (newVal) {
        this.getConnect(this.idClear)
      }
    },
    searchRequest(newVal) {
      this.requestTerm = newVal
    },
    platformId(newVal) {
      this.platId = newVal
    }
  },
  methods: {
    // 父子组件回调
    check() {
      this.showDialog = false
      // 判断是否取消关联了
      if (this.requestTerm) {
        this.$emit('closeConnect', this.requestTerm)
      } else {
        this.$emit('closeConnect')
      }
    },
    // 查询关联列表
    getConnect(id) {
      const param = {
        // token: this.token,
        userCenterId: id
      }
      console.log('请求参数')
      console.log(param)
      if (this.connectDialog) {
        connect(secret.Encrypt(param)).then(response => {
          var data = response.data
          console.log('返回结果')
          console.log('response')
          this.list = data.list
        })
      }
    },
    // 查看
    watch(id, platIdd) {
      // this.showDialog = false // 关闭弹窗
      this.dialogTableVisible = true
      this.idd = id
      this.platIdd = platIdd
    },
    // 父子组件回调
    closeDialog() {
      this.dialogTableVisible = false
    },
    cancelConnect(scope) {
      console.log(scope)
      var that = this
      this.$confirm('确定要取消关联吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const param = {
          // token: this.token,
          userCenterId: scope.userCenterId,
          userId: scope.userId,
          platformId: scope.platformId
        }
        this.sitation = true
        console.log('请求参数')
        console.log(param)
        cancel(secret.Encrypt(param)).then(response => {
          console.log('返回结果')
          console.log(response)
          that.$message({
            message: '取消成功',
            type: 'success'
          })
          that.getConnect(scope.userCenterId)
        })
      }).catch(() => {
        console.log('取消失败')
      })
    }
  }
}
</script>
<style scoped>

</style>
